package com.zhihu_lvliangi_android.option.general;

import java.util.List;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.zhihu_lvliangi_android.R;
import com.zhihu_lvliangi_android.option.parent.ParentFragment;
import com.zhihu_lvliangi_android.option.zhengwu.adapter.TabPagerAdapter;
import com.zhihu_lvliangi_android.util.Constant;
import com.zhihu_lvliangi_android.view.PagerSlidingTabStrip;

public class GeneralTabSlidingFragment extends ParentFragment {

	private PagerSlidingTabStrip pagerSlidingTabStrip;
	private ViewPager public_ViewPager;
	private TabPagerAdapter adapter;
	private List<ParentFragment> mFragments ;
//	private List<Fragment> mFragments ;
	private List<String> mTabTitles ;
	private View mParetView;
	
	public static GeneralTabSlidingFragment newInsatnce(List<ParentFragment> mFragments,List<String> mTabTitles){
		GeneralTabSlidingFragment fragment = new GeneralTabSlidingFragment();
		Bundle bundle = new Bundle();
		Object[] objects ={mFragments,mTabTitles};
		bundle.putSerializable(Constant.GENERAL_SAVE_KEY,objects);
		fragment.setArguments(bundle);
		return fragment;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		setUseMain_scrollview(false);//不加入scrollView ,否则有问题
		super.onCreate(savedInstanceState);
		Object[] objects = (Object[]) getArguments().getSerializable(Constant.GENERAL_SAVE_KEY);
		mFragments =  (List<ParentFragment>) objects[0];
		//.addAll(Arrays.asList(getResources().getStringArray(R.array.zhengwu_catergory)))
		mTabTitles = (List<String>) objects[1];
	}
	

	private void initView(View parentView) {
		mParetView = parentView; 
		pagerSlidingTabStrip = (PagerSlidingTabStrip) parentView
				.findViewById(R.id.guide_fragment_PagerSlidingTabStrip);
		public_ViewPager = (ViewPager) parentView
				.findViewById(R.id.guide_fragment_ViewPager);
		public_ViewPager.setOffscreenPageLimit(2);
		pagerSlidingTabStrip.setBackgroundColor(Color.parseColor(getString(R.color.viewpager_tab_bg)));
		pagerSlidingTabStrip.setUnderlineColorResource(R.color.gray);
		pagerSlidingTabStrip.setUnderlineHeight(1);
		pagerSlidingTabStrip.setIndicatorHeight(5);
		
		pagerSlidingTabStrip
				.setIndicatorColorResource(R.color.viewpager_tab_bg_selected);
		pagerSlidingTabStrip
				.setTextColorResource(R.drawable.viewpager_tab_text_selector);
		adapter = new TabPagerAdapter(getChildFragmentManager(),
				mFragments, mTabTitles);
		// 设置Adapter
		public_ViewPager.setAdapter(adapter);
		pagerSlidingTabStrip.setViewPager(public_ViewPager);
	}

	@Override
	protected int getLayoutId() {
		return R.layout.fragment_affair_guid;
	}

	@Override
	protected void setupViews(View parentView) {
	initView(parentView);	
	}

	@Override
	protected void initialized(Bundle savedInstanceState) {
		
	}

	@Override
	public void threadTask() {
		
	}

	
}
